package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SpZu;
import com.ruoyi.system.service.ISpZuService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 分组信息Controller
 * 
 * @author ruoyi
 * @date 2022-11-11
 */
@RestController
@RequestMapping("/system/zu")
public class SpZuController extends BaseController
{
    @Autowired
    private ISpZuService spZuService;

    /**
     * 查询分组信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:zu:list')")
    @GetMapping("/list")
    public AjaxResult list(SpZu spZu)
    {
        List<SpZu> list = spZuService.selectSpZuList(spZu);
        return AjaxResult.success(list);
    }

    /**
     * 导出分组信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:zu:export')")
    @Log(title = "分组信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpZu spZu)
    {
        List<SpZu> list = spZuService.selectSpZuList(spZu);
        ExcelUtil<SpZu> util = new ExcelUtil<SpZu>(SpZu.class);
        util.exportExcel(response, list, "分组信息数据");
    }

    /**
     * 获取分组信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:zu:query')")
    @GetMapping(value = "/{zuId}")
    public AjaxResult getInfo(@PathVariable("zuId") Long zuId)
    {
        return AjaxResult.success(spZuService.selectSpZuByZuId(zuId));
    }

    /**
     * 新增分组信息
     */
    @PreAuthorize("@ss.hasPermi('system:zu:add')")
    @Log(title = "分组信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpZu spZu)
    {
        return toAjax(spZuService.insertSpZu(spZu));
    }

    /**
     * 修改分组信息
     */
    @PreAuthorize("@ss.hasPermi('system:zu:edit')")
    @Log(title = "分组信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpZu spZu)
    {
        return toAjax(spZuService.updateSpZu(spZu));
    }

    /**
     * 删除分组信息
     */
    @PreAuthorize("@ss.hasPermi('system:zu:remove')")
    @Log(title = "分组信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{zuIds}")
    public AjaxResult remove(@PathVariable Long[] zuIds)
    {
        return toAjax(spZuService.deleteSpZuByZuIds(zuIds));
    }
}
